package com.czp.dict.action;

import com.czp.dict.model.Dict;
import com.czp.dict.model.DictType;
import com.czp.dict.service.IDictService;
import com.czp.framework.action.BaseActionSupport;
import com.czp.framework.exception.IServiceException;

/**
 * 【环 境】：J2SE 1.7
 * @author   柴志鹏	CHAIZP@GMAIL.COM
 * @version  version 1.0
 * @since    2014-8-5
 */
public class DictAction extends BaseActionSupport {
	private static final long serialVersionUID = -6775915440678927252L;
	private IDictService dictService;
	private DictType dictType;
	
	/** 
	 * 【描 述】：查询字典 "类型"
	 */
	public void getDictTypeList() {
		try {
			DictType dictType = new DictType();
			dictType.setStart(Integer.parseInt(request.getParameter("start")));
			dictType.setLimit(Integer.parseInt(request.getParameter("limit")));
			dictType.setDictName(request.getParameter("dictName"));
			this.responseOutPrint(
					dictService.getDictTypeList(dictType));
		} catch(Exception e) {
			throw new IServiceException(this.getClass()+ "getDictTypeList", e);
		}
	}
	
	/** 
	 * 【描 述】：查询字典 "数值"
	 */
	public void getDictList() {
		try {
			Dict dict = new Dict();
			dict.setStart(Integer.parseInt(request.getParameter("start")));
			dict.setLimit(Integer.parseInt(request.getParameter("limit")));
			dict.setDictTypeId(request.getParameter("dictTypeId"));
			this.responseOutPrint(
					dictService.getDictList(dict));
		} catch(Exception e) {
			throw new IServiceException(this.getClass()+ "getDictList", e);
		}
	}
	
	/** 
	 * 【描 述】：字典 "类型" 添加、修改、删除方法
	 */
	public void dictTypeController() {
		try {
			int count = dictService.dictTypeController(dictType);
			this.responseOutPrint("{success: "+ count +"}");
		} catch(Exception e) {
			throw new IServiceException(this.getClass()+ "dictTypeController", e);
		}
	}
	
	/** 
	 * 【描 述】：字典 "数值" 添加、修改、删除操作方法
	 */
	public void dictController() {
		try {
			String jsonData = request.getParameter("jsonData");
			int count = dictService.dictController(jsonData);
			this.responseOutPrint("{success: "+ count +"}");
		} catch(Exception e) {
			throw new IServiceException(this.getClass()+ "dictController", e);
		}
	}
	
	/**
	 * 获取 dictService
	 * @return 返回 dictService
	 */
	public IDictService getDictService() {
		return dictService;
	}
	/**
	 * 设置 dictService
	 * @param 对dictService进行赋值
	 */
	public void setDictService(IDictService dictService) {
		this.dictService = dictService;
	}

	/**
	 * 获取 dictType
	 * @return 返回 dictType
	 */
	public DictType getDictType() {
		return dictType;
	}

	/**
	 * 设置 dictType
	 * @param 对dictType进行赋值
	 */
	public void setDictType(DictType dictType) {
		this.dictType = dictType;
	}
	
}
